﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hongapo_Common;
using System.Text;

public partial class goods : Hongapo_Services.UIPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        new Hongapo_Services.Product.Product().UpdateClicks(ID); // 刷新点击
        if (!IsPostBack)
        {
            if (ID!=0)
            {
                LoadContent();
            }
        }
    }
    public int ID
    {
        get
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                return TypeConvert.ToInt32(Request["id"]);
            }
            else
            {
                return 0;
            }

        }
    }

    #region 加载资讯内容
    /// <summary>
    /// 加载资讯内容
    /// </summary>
    private void LoadContent()
    {
        StringBuilder str = new StringBuilder();
        StringBuilder str_comment = new StringBuilder();
        string path = "images/product/";
        Hongapo_Services.Product.Product pro = new Hongapo_Services.Product.Product();
        DataSet ds = pro.GetList(1, 1, " ID=" + ID + " ");
        DataTable dt = ds.Tables[0];
        DataRow dr = dt.Rows[0];
        this.Page.Title = dr["Title"].ToString();
        DataTable dt_mall = new Hongapo_Services.Mall.Mall().GetList(" ID=" + dr["MID"] + "").Tables[0];
        DataTable dt_img = new Hongapo_Services.Product.ProductImage().GetList(" OrderNo='" + dr["OrderNo"] + "' and isopen=1").Tables[0];
        str.Append(" <div class=\"info\" style=\"height:100%;\"  ><div class=\"news_qtlg\" style=\"height:auto;\"><div class=\"lf_indtype\">");
        str.Append("<h2 style=\"text-align:center\">" + dr["Title"] + "</h2>");
        str.Append(" <p class=\"dat_fb\">" + dr["AuditName"] + " 发布于 " + dr["Createdate"] +
            " | " + dr["clicks"] + " 次阅读 | " + dr["commentCount"] + " 次评论 |  <a href=\"" + dr["LinkUrl"] + "\" target=\"_blank\"><span style=\"color:red;font-weight:bold\">立即购买</span></a></p>");
        str.Append("<div class=\"dt_ft\"> <p >" + dr["InfoDesc"] + "</p></div></div>");
        str.Append("<p class=\"img\"><img src=\"images/mall/" + dt_mall.Rows[0]["logo"] + "\" alt=\"" + dt_mall.Rows[0]["Title"] + "\" /></p></div>");
        str.Append(" <div class=\"pic_pro\" id=\"procontent\" style=\"text-align:center\" name=\"#img\">");
        str.Append("<div class=\"CRviewer\"> <img  id=\"myImgs\"/><div style=\"display:none\" id=\"imgpath\">");
        foreach (DataRow dr_img in dt_img.Rows)
        {
            str.Append("<span>" + path + dr_img["BigImg"] + "</span>");
        }
        str.Append("</div><div class=\"hoverNav\"><a class=\"prevLink\" href=\"#img\" ></a><a class=\"nextLink\"  href=\"#img\"></a></div> </div>");
        str.Append("</div><div class=\"bm_indtype\"></div></div>");

        // 加载评论

        DataSet ds_comment = new Hongapo_Services.Product.Comment().GetList(100, 1, " PID=" + ID + " and isopen=1 "," ID");
        str_comment.Append("<div class=\"commentTite\" name=\"comment\">共 " + ds_comment.Tables[0].Rows.Count + " 条评论</div><div id=\"n_content\">");
         int index = 0;
        foreach (DataRow dr_comment in ds_comment.Tables[0].Rows)
        {
            index++;
            str_comment.Append("<dl>");
            str_comment.Append("<dt class=\"h_author\"><span><strong >第" + index + "楼：</strong> " + dr_comment["UserName"] + " 发表于 " + dr_comment["CreateDate"] + "</span></dt>");
            str_comment.Append("<dd class=\"h_content\">" + dr_comment["content"] + "</dd>");
            str_comment.Append("</dl>");

        }
        str_comment.Append("</div>");

        this.ltlContent.Text = str.ToString();
        this.ltlComment.Text = str_comment.ToString();
        this.ltlHot.Text = CreateHotGoods();
    }
    #endregion

    /// <summary>
    /// 发表评论
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSend_Click(object sender, EventArgs e)
    {
        Hongapo_Model.Product.Comment model = new Hongapo_Model.Product.Comment();
        Hongapo_Services.Product.Comment bll = new Hongapo_Services.Product.Comment();
        model.Content = this.txtComment.Text;
        model.Createdate = DateTime.Now;
        model.Email = this.txtMail.Text;
        model.Isopen = 1;
        model.PID = ID;
        model.HomeURL = Hongapo_Common.objectHandlers.GetIP();// IP
        model.UserName = string.IsNullOrEmpty(this.txtName.Text) == true ? "匿名人士" : this.txtName.Text;
        bll.Add(model);
        Response.Redirect("goods.aspx?id="+ID+"#comment");
    }
}
